<?php
App::uses('TwitterComponent', 'Controller/Component');
App::uses('ComponentCollection', 'Controller');

class TwitterComponentTest extends CakeTestCase {
	public function setUp(){
		parent::setUp();
		Configure::load("my_conf");

		$user = Configure::read("Twitter.user");
		$pass= Configure::read("Twitter.pass");
		// Setup our component and take test controller
		$Collection = new ComponentCollection();
		$this->Twitter = new TwitterComponent($Collection);

	}

	public function testConstruct(){
		$this->assertNotNull($this->Twitter);
		$this->assertInstanceOf('TwitterComponent',$this->Twitter);
	}

	public function testTest(){
		$expected = "<ok>true</ok>";
		$result = $this->Twitter->test('xml');
		$msg = "result:".($result)."\n".
			"expected:".($expected);

		$this->assertEquals($result, $expected,$msg);
	}

	public function testSearch(){
		$options = array('q'=>'camobile');
		$result = $this->Twitter->search($options,'rss');

		$this->assertArrayHasKey('rss', $result);
		$this->assertArrayHasKey('title', $result['rss']['channel']);
		$this->assertArrayHasKey('pubDate', $result['rss']['channel']);
		$this->assertArrayHasKey('link', $result['rss']['channel']);
		$this->assertArrayHasKey('description', $result['rss']['channel']);
		$this->assertArrayHasKey('title', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('link', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('description', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('pubDate', $result['rss']['channel']['item'][0]);
	
		$this->assertNotEmpty($result);

	}

	public function testGetPublicTimeLine(){
		$result = $this->Twitter->getPublicTimeline();

		$this->assertArrayHasKey('rss', $result);
		$this->assertArrayHasKey('title', $result['rss']['channel']);
		$this->assertArrayHasKey('link', $result['rss']['channel']);
		$this->assertArrayHasKey('description', $result['rss']['channel']);
		$this->assertArrayHasKey('title', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('link', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('description', $result['rss']['channel']['item'][0]);
		$this->assertArrayHasKey('pubDate', $result['rss']['channel']['item'][0]);
		$this->assertNotEmpty($result);

	}


}
